import { defineStore } from 'pinia'

export const useContent = defineStore('content', {
  state: () => ({
    items: [], // 目录项
    anchors: [], // 对应锚点
    types: [], // 1为加粗 2标准 3缩进
  }),
  actions: {
    init() {
      this.items = []
      this.anchors = []
      this.types = []
      return this
    },
    // 设置
    setContent(items, anchors, types) {
      this.items = items
      this.anchors = anchors || []
      this.types = types || []
    },
    // 添加
    addContent(items, anchors, types) {
      this.items.push(...items)
      this.anchors.push(...(anchors || []))
      this.types.push(...(types || items.map(() => 2)))
    }
  },
})